package it.antonio.ilpizze.swing.util;

import java.util.List;

import javax.swing.ComboBoxModel;

public abstract class SimpleComboBoxModel<T> extends SimpleListModel<T> implements ComboBoxModel, Iterable<T>{

	private static final long serialVersionUID = 1L;
	private Object selectedItem;
	
	public SimpleComboBoxModel(List<T> list) {
		super(list);
		if(list.size() > 0){
			selectedItem = toDescriptionString(list.get(0));
		}
	}

	public SimpleComboBoxModel(T... list) {
		super(list);
		if(list.length > 0){
			selectedItem = toDescriptionString(list[0]);
		}
	}

	@Override
	public Object getSelectedItem() {
		return selectedItem;
	}
	
	@Override
	public void setSelectedItem(Object selected) {
		selectedItem = selected;
		fireContentsChanged(this, -1, -1);
	}
	
}
